#include <bits/stdc++.h>
#define debug(x) cerr << "\tDEBUG: " << #x << " = " << (x) << endl
using namespace std;

template <typename T>
inline bool tomin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T>
inline bool tomax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
inline void Rd(T &res)
{
	static char c;
	res = 0;
	while ((c = getchar()) < 48)
		;
	do
		res = (res << 1) + (res << 3) + (c ^ 48);
	while ((c = getchar()) > 47);
}
const int maxn = 3e6 + 100;
bool cur1;
int n, q;
char str[maxn];
int sum[maxn];

struct node
{
	int fa, mx, mn, ans;
} A[maxn];

struct query
{
	int l, r;
} C[maxn], Q[maxn];

int cnt[maxn];
inline void Sort()
{
	for (int i = 1; i <= q; i++)
		cnt[C[i].r]++;
	for (int i = 2; i <= n; i++)
		cnt[i] += cnt[i - 1];
	for (int i = q; i >= 1; i--)
		Q[cnt[C[i].r]--] = C[i];
}
int getfa(int x)
{
	if (A[x].fa != x)
	{
		int t = getfa(A[x].fa);
		tomax(A[x].ans, max(A[A[x].fa].mx - A[x].mn, A[A[x].fa].ans));
		tomax(A[x].mx, A[A[x].fa].mx);
		tomin(A[x].mn, A[A[x].fa].mn);
		A[x].fa = t;
	}
	return A[x].fa;
}
bool cur2;
int main()
{
	
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	cin >> n >> q;
	scanf("%s", str + 1);
	for (int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + (str[i] == '0' ? -1 : 1);
		A[i].fa = i;
		A[i].mn = A[i].mx = sum[i];
	}
	for (int i = 1; i <= q; i++)
	{
		Rd(C[i].l);
		Rd(C[i].r);
	}
	Sort();
	int ans = 0;
	for (int i = 1, l, r; i <= q; i++)
	{
		r = Q[i].r;
		l = Q[i].l;

		for (int nxt = getfa(l); nxt != r; nxt = getfa(l))
		{
			A[nxt].fa = nxt + 1;
		}

		int res = max(A[l].mx - sum[l - 1], A[l].ans) - (sum[r] - sum[l - 1]);
		if (sum[r] - sum[l - 1] + res == 0)
			res++;
		ans ^= res;
	}
	printf("%d\n", ans);
	return 0;
}